package com.rds.web.controller.pms;

import com.rds.common.annotation.Log;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.page.TableDataInfo;
import com.rds.common.enums.BusinessType;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.system.domain.RdaPortalArea;
import com.rds.system.service.IRdaPortalAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * portal区域Controller
 *
 * @author rds
 * @date 2021-10-22
 */
@RestController
@RequestMapping("/pms/portalarea")
public class RdaPortalAreaController extends BaseController
{
    @Autowired
    private IRdaPortalAreaService rdaPortalAreaService;

    /**
     * 查询portal区域列表
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaPortalArea rdaPortalArea)
    {
        List<RdaPortalArea> list = rdaPortalAreaService.selectRdaPortalAreaList(rdaPortalArea);
        return getDataTable(list);
    }

    /**
     * 导出portal区域列表
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:export')")
    @Log(title = "portal区域", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaPortalArea rdaPortalArea)
    {
        List<RdaPortalArea> list = rdaPortalAreaService.selectRdaPortalAreaList(rdaPortalArea);
        ExcelUtil<RdaPortalArea> util = new ExcelUtil<RdaPortalArea>(RdaPortalArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取portal区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaPortalAreaService.selectRdaPortalAreaById(id));
    }

    /**
     * 新增portal区域
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:add')")
    @Log(title = "portal区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaPortalArea rdaPortalArea)
    {
        return toAjax(rdaPortalAreaService.insertRdaPortalArea(rdaPortalArea));
    }

    /**
     * 修改portal区域
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:edit')")
    @Log(title = "portal区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaPortalArea rdaPortalArea)
    {
        return toAjax(rdaPortalAreaService.updateRdaPortalArea(rdaPortalArea));
    }
    /**
     * 关联portal区域 和 portal
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:edit')")
    @Log(title = "portal区域", businessType = BusinessType.UPDATE)
    @PutMapping("/link")
    public AjaxResult link(@RequestBody RdaPortalArea rdaPortalArea)
    {
        return toAjax(rdaPortalAreaService.updateRdaPortalArea2portal(rdaPortalArea));
    }
    /**
     * 删除portal区域
     */
    @PreAuthorize("@ss.hasPermi('pms:portalarea:remove')")
    @Log(title = "portal区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaPortalAreaService.deleteRdaPortalAreaByIds(ids));
    }
}
